﻿Type.registerNamespace("SysCore.Web.UI");

jQueryNET.Controls.ToolBar = function jQueryNET$Controls$ToolBar(element, createSelf) {
	jQueryNET.Controls.ToolBar.initializeBase(this, [element]);
}

jQueryNET.Controls.ToolBar.createElement = function(parent) {
	var element =
		$(parent)
			.append('<div class="toolbar no_border">' +
					'<table cellspacing="0">' +
					'<tbody>' +
					'<tr></tr>' +
					'</tbody>' +
					'</table>' +
					'</div>')
			.find('div.toolbar:last');

	return element.get(0);
}

function jQueryNET$Controls$ToolBar$initialize() {
	jQueryNET.Controls.ToolBar.callBaseMethod(this, "initialize");

	this._tableRowElement = $(this.get_element()).find('tr');
	
	this.refresh();
}

function jQueryNET$Controls$ToolBar$dispose() {
	jQueryNET.Controls.ToolBar.callBaseMethod(this, "dispose");
}


function jQueryNET$Controls$ToolBar$get_items() {
	if (arguments.length !== 0) throw Error.parameterCount();
	return this._items;
}

function jQueryNET$Controls$ToolBar$set_items(value) {
	var e = Function._validateParams(arguments, [{ name: "value", type: Array, mayBeNull: false}]);
	if (e) throw e;

	this._items = value;
}

function jQueryNET$Controls$ToolBar$get_controls() {
	if (arguments.length !== 0) throw Error.parameterCount();
	return this._controls;
}

function jQueryNET$Controls$ToolBar$refresh() {
	if (arguments.length !== 0) throw Error.parameterCount();

	Array.forEach(this.get_items(), function(element, index, array) {
		var owner = this._tableRowElement.append('<td></td>').find('td:last');
		if (element.type != null)
		    this._controls.push(
			    $create(
				    element.type,
				    element.properties,
				    element.events,
				    element.references,
				    element.type.createElement(owner))
		);
	}, this);
}

function jQueryNET$Controls$ToolBar$addButton(title, className, clickDelegate) {
	var owner = $(this.get_element()).find('tr');
	
	owner.append('<td>Button</td>');
}

function jQueryNET$Controls$ToolBar$addSeparator() {
	var owner = $(this.get_element()).find('tr');
	
	owner.append('<td>Separator</td>');
}

function jQueryNET$Controls$ToolBar$addControl(control) {
	var owner = $(this.get_element()).find('tr');
	
	owner.append('<td>Control</td>');
}

jQueryNET.Controls.ToolBar.prototype = {
	_items: new Array(),
	_controls: new Array(),
	_tableRowElement: null,
	
	initialize: jQueryNET$Controls$ToolBar$initialize,
	dispose: jQueryNET$Controls$ToolBar$dispose,

	get_items: jQueryNET$Controls$ToolBar$get_items,
	set_items: jQueryNET$Controls$ToolBar$set_items,
	get_controls: jQueryNET$Controls$ToolBar$get_controls,
	
	refresh: jQueryNET$Controls$ToolBar$refresh,
	addButton: jQueryNET$Controls$ToolBar$addButton,
	addSeparator: jQueryNET$Controls$ToolBar$addSeparator,
	addControl: jQueryNET$Controls$ToolBar$addControl
}

jQueryNET.Controls.ToolBar.registerClass("jQueryNET.Controls.ToolBar", jQueryNET.Controls.ControlBase);